<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>芳小微宣</title>
    <link rel="stylesheet" href="css/index.css">
    <style type="text/css">
        html,body{
            width: 100%;
            height: 100%;
        }
    </style>
    <script src="js/jquery.min.js"></script>
    <script src="js/index.js"></script>
    <script src="js/jquery.cookie.js"> </script>
</head>
<body>
<div class="htmleaf-container">
    <header class="htmleaf-header bgcolor-11">
        <div style="text-align:center;clear:both;">
             <span class="dataPrev"><img src="images/left.png" style="width: 15px"></span>
             <span style="font-size: 5rem"><span class="firstDay"></span>-<span class="lastDay"></span></span>
             <span class="dataNext"><img src="images/right.png" style="width: 15px"></span>
        </div>
    </header>
    <div class="mobile">
        <ul class="sidenav">
            <li class="weekClick" style="line-height: 25px;position: relative;background: #80cf02"><div class="mainWeek">本周主要工作</div></li>
            <li class="weekClick"><a href="#">星期一</a></li>
            <li class="weekClick"><a href="#">星期二</a></li>
            <li class="weekClick"><a href="#">星期三</a></li>
            <li class="weekClick"><a href="#">星期四</a></li>
            <li class="weekClick"><a href="#">星期五</a></li>
            <li class="weekClick"><a href="#">备注</a></li>
        </ul>
        <section>
           <!-- <label for="tm" id="chaTab">Click Me</label>-->
            <div id="chaTab">
                <img id="tabChange" src="images/list.png" style="width: 20px;margin: 10px;"/>
                <span class="weekTit">本周主要工作</span>
            </div>
            <div class="cont_week" style="display: block"></div>
            <div class="cont_week"></div>
            <div class="cont_week"></div>
            <div class="cont_week"></div>
            <div class="cont_week"></div>
            <div class="cont_week"></div>
            <div class="cont_week"></div>
        </section>
    </div>
    <div class="returnBtn">
        <a href="index.html">
            <img src="images/return.png" style="width: 25px;padding-top: 4px;"><br>
            <span>返回</span>
        </a>
    </div>
</div>
<script>
    $(function(){
        $("section").css("height",$("body").height()-101);

        /*$(".firstDay").html(getWeekStartDate(0));
        $(".lastDay").html(getWeekEndDate(2));
*/
        initData(getWeekStartDate(0),getWeekEndDate(2))
        /*$.ajax({
            type : "POST",
            url : path + "/api/weixin/getWeekPlan?token=" + window.localStorage.getItem('token'),
            data : {},
            dataType : 'json',
            success : function(msg) {
                if(msg.code == 501){
                    window.location.href = "login.html";
                    return;
                };
                $(".cont_week").eq(0).html(msg.workPlanEntity.weekPlan.replace(/\n/g,'<br>'));
                $(".cont_week").eq(6).html(msg.workPlanEntity.remark.replace(/\n/g,'<br>'));
                for(var i=0;i<msg.workPlanInfoEntity.length;i++){
                    $(".cont_week").eq(i+1).html(msg.workPlanInfoEntity[i].dayPlan.replace(/\n/g,'<br>'));
                }
            }
        })*/
    });
    var num=0;
    $("#tabChange").click(function(){
        if(num%2 == 0){
            $("section").css("transform","translateX(100px)")
        }else{
            $("section").css("transform","translateX(0)")
        }
        num++;
    });
    $(".weekClick").click(function(){
        num++;
        $(".weekClick").css("background","#707070");
        $(this).css("background","#80cf02");
        $(".weekTit").html($(this).text());

        $(".cont_week").css("display","none");
        $(".cont_week").eq($(this).index()).css("display","block");
        $("section").css("transform","translateX(0)");

    });
    $(".dataPrev").click(function(){
        //点击前一页 后一页   刷新页面内容
        upWeek();

    });
    $(".dataNext").click(function(){
        //点击前一页 后一页   刷新页面内容
        downWeek()
    });
    function initData(date,enddate){
        $(".firstDay").html(date);
        $(".lastDay").html(enddate);

        $.ajax({
            type : "POST",
            url : path + "/api/weixin/getWeekPlan?token=" + window.localStorage.getItem('token'),
            data : {
                "date":date
            },
            dataType : 'json',
            success : function(msg) {
                if(msg.code == 0){
                    if(msg.workPlanEntity){
                        $(".cont_week").eq(0).html(msg.workPlanEntity.weekPlan.replace(/\n/g,'<br>'));
                        $(".cont_week").eq(6).html(msg.workPlanEntity.remark.replace(/\n/g,'<br>'));
                        for(var i=0;i<msg.workPlanInfoEntity.length;i++){
                            $(".cont_week").eq(i+1).html(msg.workPlanInfoEntity[i].dayPlan.replace(/\n/g,'<br>'));
                        }
                    }else{
                        $(".cont_week").html('<div class="nodata"><img src="images/nodata.png"/><br>暂无数据</div>');
                    }

                }else  if(msg.code == 501){
                    window.location.href = "login.html";
                    return;
                };
            }
        })
    }

    var now = new Date();                    //当前日期
    var nowDayOfWeek = now.getDay();         //今天本周的第几天
    var nowDay = now.getDate();              //当前日
    var nowMonth = now.getMonth();           //当前月
    var nowYear = now.getYear();             //当前年

    var count=1;
    //获取上周
    function upWeek(){
       /* changeWeek(7*count);
        changeMonth(7*count);*/
        if(count==0){
            console.log(getWeekStartDate(0))
            console.log(getWeekEndDate(2))
            initData(getWeekStartDate(0),getWeekEndDate(2))
        }else if(count<0){
            console.log(getWeekStartDate(7*count))
            console.log(getWeekEndDate((7*count)+2))
            initData(getWeekStartDate(7*count),getWeekEndDate((7*count)+2))
        }else{
            console.log(getWeekStartDate(7*count))
            console.log(getWeekEndDate((7*count)+2),getWeekStartDate(7*count))
            initData(getWeekStartDate(7*count),getWeekEndDate((7*count)+2))
        }
        count++;
    }
    //获取下周
    function downWeek(){
        /*changeWeek((7*(count-1))-7);
        changeMonth((7*(count-1))-7);*/
        if(count==2){
            console.log(getWeekStartDate(0))
            console.log(getWeekEndDate(2))
            initData(getWeekStartDate(0),getWeekEndDate(2))
        }else if(count>2){
            console.log(getWeekStartDate((7*(count-1))-7))
            console.log(getWeekEndDate(((7*(count-1))-5)))
            initData(getWeekStartDate((7*(count-1))-7),getWeekEndDate(((7*(count-1))-5)))
        }else{
            console.log(getWeekStartDate((7*(count-1))-7))
            console.log(getWeekEndDate(((7*(count-1))-5)))
            initData(getWeekStartDate((7*(count-1))-7),getWeekEndDate(((7*(count-1))-5)))
        }
        count--;
    }

    //获取当前周第一天
    function getWeekStartDate(i){
        return formatDate(new Date(now.getFullYear(), nowMonth, nowDay - nowDayOfWeek-i+1));
    }

    //获取当前周最后一天
    function getWeekEndDate(i){
        return formatDate(new Date(now.getFullYear(), nowMonth, nowDay + (6 - nowDayOfWeek-i)+1));
    }
</script>
</body>
</html>